package util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

public class PrintMessage {
	public static void getMessage(HttpServletRequest request,String msg){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		File file=new File("E:/loginMessage.txt");
		PrintWriter pw=null;
		Date date=new Date();
		try {
			pw=new PrintWriter(new OutputStreamWriter(new FileOutputStream(file,true)));
			if(!file.exists()){
				file.createNewFile();
			}
			String str=sdf.format(date);
			pw.println(str+"\tIP "+request.getRemoteAddr()+msg);		
			pw.flush();		
			pw.close();		
			} catch (IOException e) {
				e.printStackTrace();
			}
	}
}
